// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import global from "../global";
import FlyObj from "./FlyObj";
import config from "../config"
const { ccclass, property } = cc._decorator;

@ccclass
export default class SpaceStation extends FlyObj {//行星类，飞船环绕的星球

    public Havespaceship: number = 0;//不知道有没有用，先标记上
    public thisPlanet: NodeInfoPara = null;
    // LIFE-CYCLE CALLBACKS:

    //主场景音效资源
    @property({
        type: cc.AudioClip,
        tooltip: "grabsound",
        displayName: "grabsound",
    })
    grabaudio: cc.AudioClip = null;
    onLoad() {
        super.onLoad();

        this.node.name = "SpaceStation";
        this.circleCollider.name = "SpaceStation";
        this.nodeName = "SpaceStation";

        const thisPlanetInfo: NodeInfoPara =
        {
            x: 0, //this.randomNum(global.Xrange[0],global.Xrange[1]),
            y: -500,
            scaleX: 1,
            scaleY: 1,
            width: 100,
            height: 100
        };
        this.thisPlanet = thisPlanetInfo;
        this.setInfo(this.thisPlanet);

        // this.setPhoto(config.spaceStationURL);
        this.setLocalPhoto("images/flyobj/Earth");

        // this.ObjSprite.node.setPosition(this.thisPlanet.x, this.thisPlanet.y);  // 在没有父节点的情况下set容易出问题。
    }

    start() {
        super.start();
    }

    //update(dt){}
    randomNum(Min, Max) {
        //获取随机值
        var Range = Max - Min;
        var Rand = Math.random();
        var num = Min + Math.floor(Rand * Range);
        return num;
    }

    onCollisionEnter(other, self) {
        // console.log(other.node);
        if (this.grabaudio) cc.audioEngine.playEffect(this.grabaudio, false); //播放捕获飞行器的音效
        //下面需要画布下拉
    }
    // update (dt) {}
}
